#ifndef __CPPTUTORLOG_H__
#define __CPPTUTORLOG_H__

#include <fstream>
#include <iostream>
#include <string>
#include <time.h>

using std::string;
using std::ofstream;
using std::ios_base;

using namespace std;
 
// he log file has to be accessed from any code
// which includes this header (similiar to cout, cerr, clog, etc..)

//class   CcppTutorLog;
//extern  CcppTutorLog Log;

// const string SD_DEFAULT_LOGFILE = "ccplusplus.log";

const int LOG_WRITE  = ios::out;
const int LOG_APPEND = ios::app;

const int EXIT_MSG_SIZE = 512;
const int MAX_EXIT_CODES = 3;

class CcppTutorLog : public ofstream
{
    public:
        enum logLevels 
        {
            LEVEL_0,       // buffer all log messages
            LEVEL_1,       // buffer Level one, two and three log messages
            LEVEL_2,       // buffer Level two and three log messages
            LEVEL_3,       // buffer Level three log messages
            QUIET_MODE     // do not print out any messages
        };
 
        CcppTutorLog();
        CcppTutorLog(const string&);
        CcppTutorLog(const string&,enum logLevels);
        virtual ~CcppTutorLog();

    private:
        void initVars();
        void init(const string&);
        void init(const string&,int);
        void init();

        char* getExecTime();
        void  getExecTime(int*,int*);
        void  openLog(const string&,int);
        void  printHeader(int);

    private:
        string logName;
        enum logLevels logLevel;
        time_t startTime;
};
extern  CcppTutorLog Log;

const enum CcppTutorLog::logLevels L0 = CcppTutorLog::LEVEL_0;
const enum CcppTutorLog::logLevels L1 = CcppTutorLog::LEVEL_1;
const enum CcppTutorLog::logLevels L2 = CcppTutorLog::LEVEL_2;
const enum CcppTutorLog::logLevels L3 = CcppTutorLog::LEVEL_3;
const enum CcppTutorLog::logLevels LQUIET = CcppTutorLog::QUIET_MODE;

#endif //__CPPTUTORLOG_H__


